Skip to content

bugfix(supply): Implement proportional supply bonus scaling to fix too generous money deposits for partial supply drops#2431

Merged
xezon merged 1 commit intoTheSuperHackers:mainfrom
tintinhamans:arctic/propo-supply-bonus
Mar 14, 2026
Merged

bugfix(supply): Implement proportional supply bonus scaling to fix too generous money deposits for partial supply drops#2431
xezon merged 1 commit intoTheSuperHackers:mainfrom
tintinhamans:arctic/propo-supply-bonus

Conversation

@tintinhamans
Copy link

@tintinhamans tintinhamans commented Mar 9, 2026

@greptile-apps
Copy link

greptile-apps bot commented Mar 9, 2026

Greptile Summary

This PR fixes an over-generous upgrade bonus in supply delivery by extracting the bonus calculation into a new getUpgradedSupplyBoostValue helper and scaling it proportionally to deliveredBoxes / maxBoxes, gated behind #if !RETAIL_COMPATIBLE_CRC to preserve CRC parity in retail-compatible builds.

Key changes:

  • Added getMaxBoxes() as a pure virtual to SupplyTruckAIInterface and implemented it in both SupplyTruckAIUpdate and WorkerAIUpdate (reading m_maxBoxesData from module data). ChinookAIUpdate inherits the implementation correctly from SupplyTruckAIUpdate.
  • Box count is now snapshotted via getNumberBoxes() before the loseOneBox() unload loop, which is the correct order for capturing the actual delivery quantity.
  • Division by zero when MaxBoxes is unconfigured (defaults to 0) is prevented by an explicit maxBoxes > 0 guard; the fallback returns 0 rather than the full boost for units without a configured MaxBoxes.
  • Integer truncation in (upgradedSupplyBoost * deliveredBoxes) / maxBoxes is a known trade-off discussed in the previous review thread — small boost values relative to maxBoxes can round down to 0 for partial loads.
  • Changes are correctly scoped to GeneralsMD/; the vanilla Generals/ codebase is unaffected.

Confidence Score: 4/5

  • Safe to merge with minor caveats — logic is sound and previously flagged issues are addressed.
  • The core implementation is correct: box count is snapshotted before unloading, division by zero is guarded, ChinookAIUpdate inherits the new method cleanly, and the retail-CRC gate is intentional. The remaining known trade-offs (integer truncation, maxBoxes == 0 returning 0 instead of full boost) were discussed in the prior review thread and appear to be deliberate decisions by the author. No new critical issues were identified.
  • No files require special attention; SupplyCenterDockUpdate.cpp carries the most logic complexity but is well-structured.

Important Files Changed

Filename Overview
GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SupplyTruckAIUpdate.h Adds getMaxBoxes() pure virtual to SupplyTruckAIInterface and a concrete implementation in SupplyTruckAIUpdate that reads m_maxBoxesData; ChinookAIUpdate inherits the implementation correctly via SupplyTruckAIUpdateModuleData. No issues.
GeneralsMD/Code/GameEngine/Include/GameLogic/Module/WorkerAIUpdate.h Implements the new getMaxBoxes() virtual method by reading m_maxBoxesData from WorkerAIUpdateModuleData; consistent with the SupplyTruckAIUpdate counterpart. No issues.
GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyCenterDockUpdate.cpp Extracts upgrade-boost calculation into getUpgradedSupplyBoostValue, guards against division-by-zero via maxBoxes > 0, and snapshots box count before unloading for correct proportional scaling; one minor concern around deliveredBoxes > maxBoxes edge case and existing integer-truncation issue (discussed in prior thread).

Sequence Diagram

sequenceDiagram
    participant Truck as SupplyTruck / Worker / Chinook
    participant Dock as SupplyCenterDockUpdate::action
    participant AI as SupplyTruckAIInterface

    Dock->>AI: getUpgradedSupplyBoostValue()
    activate AI
    Note over AI: #if RETAIL_COMPATIBLE_CRC → full boost (unscaled)
    AI->>AI: getMaxBoxes() → maxBoxes
    alt maxBoxes > 0
        AI->>AI: getUpgradedSupplyBoost() → boost
        AI->>AI: getNumberBoxes() → deliveredBoxes
        AI-->>Dock: (boost × deliveredBoxes) / maxBoxes
    else maxBoxes == 0
        AI-->>Dock: 0
    end
    deactivate AI

    loop while loseOneBox() returns true
        Dock->>AI: loseOneBox()
        Dock->>Dock: value += getSupplyBoxValue()
    end

    Dock->>Dock: value += scaledBoost
    Dock->>Dock: deposit(value) → player money
Loading

Last reviewed commit: 378bea0

@tintinhamans tintinhamans marked this pull request as draft March 9, 2026 19:15
@tintinhamans tintinhamans force-pushed the arctic/propo-supply-bonus branch 3 times, most recently from 7bfc70d to 0f2e2bf Compare March 9, 2026 22:02
@tintinhamans tintinhamans marked this pull request as ready for review March 9, 2026 22:02
Int maxBoxes = supplyTruckAI->getMaxBoxes();
if( maxBoxes > 0 )
{
value += upgradedSupplyBoost * deliveredBoxes / maxBoxes; // Intentional integer truncation.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the idea that the supply boost is only applied up to maxBoxes?

So if we have a limit of 5 boxes but we deliver 7? we should only be applying the boost to 5 boxes?

Since the above will be under valuing the bonus if so.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nvm i misunderstood what it was doing.

But if max boxes is zero then should we be giving any kind of bonus since shouldn't it technically not be able to carry anything?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point - units with maxBoxes 0 have no business docking supplies anyways.

@tintinhamans tintinhamans force-pushed the arctic/propo-supply-bonus branch from 0f2e2bf to b87de30 Compare March 10, 2026 13:55
@tintinhamans tintinhamans force-pushed the arctic/propo-supply-bonus branch 2 times, most recently from e3eadf6 to bab6097 Compare March 10, 2026 14:34
@xezon xezon added Bug Something is not working right, typically is user facing Minor Severity: Minor < Major < Critical < Blocker ZH Relates to Zero Hour labels Mar 10, 2026
@xezon
Copy link

xezon commented Mar 10, 2026

Is this Zero Hour only?

@tintinhamans
Copy link
Author

Is this Zero Hour only?

No Supply Lines upgrade in Generals, only in ZH.

@tintinhamans tintinhamans force-pushed the arctic/propo-supply-bonus branch 2 times, most recently from 824e79e to bb5a635 Compare March 12, 2026 00:33
Copy link

@xezon xezon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code is looking good.

@tintinhamans tintinhamans force-pushed the arctic/propo-supply-bonus branch from bb5a635 to 67212ba Compare March 13, 2026 15:13
@xezon
Copy link

xezon commented Mar 14, 2026

This needs rebase.

Signed-off-by: tintinhamans <5984296+tintinhamans@users.noreply.github.com>
@tintinhamans tintinhamans force-pushed the arctic/propo-supply-bonus branch from 67212ba to 378bea0 Compare March 14, 2026 12:59
@xezon xezon changed the title bugfix(supply): Implement proportional supply bonus scaling bugfix(supply): Implement proportional supply bonus scaling to fix too generous money deposits for partial supply drops Mar 14, 2026
@xezon xezon added Nerf Makes a thing less powerful NoRetail This fix or change is not applicable with Retail game compatibility labels Mar 14, 2026
@xezon xezon merged commit b4b1cd7 into TheSuperHackers:main Mar 14, 2026
15 checks passed
@tintinhamans tintinhamans deleted the arctic/propo-supply-bonus branch March 14, 2026 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something is not working right, typically is user facing Minor Severity: Minor < Major < Critical < Blocker Nerf Makes a thing less powerful NoRetail This fix or change is not applicable with Retail game compatibility ZH Relates to Zero Hour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

USA Chinook extra money drop is always 60$ no matter how big the base money load is

3 participants